<?php

class HomePage extends Page{
    private static $db = array(
        'iFrame' => 'HTMLText'
    );
    private static $has_one = array(

    );
    private static $has_many = array(
        'Sliders' => 'Slider',
        'Partners' => 'Partner'
    );

    public function getCMSFields(){
        $fields = parent::getCMSFields();
        $fields->removeByName('Content');

        $fields->removeByName('Category');
        $sliderConfig = GridFieldConfig_RecordEditor::create()->addComponent(new GridFieldSortableRows('SortOrder'));
        $sliderGridField = new GridField(
            'Sliders',
            'Sliders',
            $this->Sliders(),
            $sliderConfig
        );
        $fields->findOrMakeTab('Root.Sliders','Sliders');
        $fields->addFieldToTab('Root.Sliders',$sliderGridField);

        $fields->findOrMakeTab('Root.VideoYoutube','Video Youtube');
        $fields->addFieldToTab('Root.VideoYoutube', new TextareaField('iFrame','iFrame'));

        $fields->findOrMakeTab('Root.Partners','Partners');
        $partnerConfig = GridFieldConfig_RecordEditor::create()->addComponent(new GridFieldSortableRows('SortOrder'));
        $partnerGridField = new GridField(
            'Partners',
            'Partners',
            $this->Partners(),
            $partnerConfig
        );
        $fields->addFieldToTab('Root.Partners',$partnerGridField);
        return $fields;
    }
}
class HomePage_Controller extends Page_Controller{

    function getArticleFeatured(){
        return Article::get()->filter(array('Featured' => true, 'Publish' => true))->sort('RAND()')->innerJoin('Article_ArticleCategories', "Article.ID = Article_ArticleCategories.ArticleID");
    }

    function getProductFeatured(){
        return EProduct::get()->filter(array('Featured' => true, 'Publish' => true));
    }
}